package persistencia;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConexaoMySQLDAO {

    private static Connection conexao = null;

    public ConexaoMySQLDAO() throws IOException {
        if (conexao == null) {
            try {
                Class.forName("com.mysql.jdbc.Driver");
                conexao = DriverManager.getConnection("jdbc:mysql://dbmy0059.whservidor.com/mecanicana3", "mecanicana3", "{carro12}");
            } catch (ClassNotFoundException e) {
                throw new IOException("Driver MySQL nao encontrado!" + e.getMessage());

            } catch (SQLException e) {
                throw new IOException("Nao foi possivel conectar ao banco: " + e.getMessage());
            }
        }
    }

    public Connection getConexao() {
        return conexao;
    }

    public void finalize() {
        try {
            conexao.close();
        } catch (Exception e) {
        }
    }
}